import sys
from PyQt6.QtWidgets import QApplication, QWidget, QComboBox, QVBoxLayout


class MainWindow(QWidget):#继承QWidget
    def __init__(self, *args, **kwargs):#self is default parameter;you can add other parameters;
        #*args is mean any parameters; *kwargs is mean any dictronary parameters;
        super().__init__()#继承执行父类的构造函数
        self.setWindowTitle("combebox组件") #set window title;be overrides the title
        ###############################################
        self.resize(400, 300)
        layout = QVBoxLayout()
        self.combo=QComboBox()#list选择一项
        self.combo.addItem("中英")
        self.combo.addItem("英中")
        self.combo.addItem("日中")
        self.combo.addItem("日英")
        self.combo.currentTextChanged.connect(self.choise)#绑定事件
        layout.addWidget(self.combo)
        self.setLayout(layout)
        ###############################################
        bg_color = kwargs.get('setbackgroundColor', None)
        if bg_color:
            self.setStyleSheet(f"background-color: {bg_color};")
        self.show()
    def choise(self):
        print(self.combo.currentText())

if __name__ == "__main__":
    #print(sys.argv) #['D:\\u\\test\\gitee\\pythonqt\\test1\\改造程序\\new_hello2.py'] print sys.argv;default is this file path.
    app=QApplication(sys.argv)#get parameters from command line.
    w=MainWindow(setbackgroundColor="lightblue") #use MainWindow created a window.
    w.setWindowTitle("combebox组件")
    w.show()#显示窗口
    #app.exec()#运行程序

    sys.exit(app.exec()) #app.exec() is first stop,then out process

    #import time #test app end,but process is not stop.
    #for i in range(10):#genarate a dictionary
    #    print(i)
    #    time.sleep(1)
# app=QApplication([])
# window=QWidget(windowTitle="Hello World",)#创建一个窗口
# window.show()#显示窗口
# app.exec()#运行程序
